﻿ <?php
require 'PasswordHash.php';
require 'key.class.php';
//	require 'key.php';
error_reporting(0);
$oText=$_POST['oText'];
//获取IP
class ip{  
    function showIp(){  
        if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown')){  
            $onlineip = getenv('HTTP_CLIENT_IP');  
        } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),'unknown')){  
             $onlineip = getenv('HTTP_X_FORWARDED_FOR');  
        } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'),'unknown')){  
            $onlineip = getenv('REMOTE_ADDR');  
        } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'],'unknown')){  
            $onlineip = $_SERVER['REMOTE_ADDR'];  
        }
    return $onlineip;  
    }
}
//超级加密函数MAIN
function jiami_main($input){
	$key="!@#<SD)SCBUkawkhdjawhd(!K!)SSK!@9";
	$input = str_replace("n", "", $input);
	$input = str_replace("t", "", $input);
	$input = str_replace("r", "", $input);
	$key = substr(md5($key), 0, 24);
	$td = mcrypt_module_open('tripledes', '', 'ecb', '');
	$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
	mcrypt_generic_init($td, $key, $iv);
	$encrypted_data = mcrypt_generic($td, $input);
	mcrypt_generic_deinit($td);
	mcrypt_module_close($td);
	return trim(
			sha1(
				md5(
					sha1(
						md5(
							chop(
								base64_encode($encrypted_data)
							)
						)
					)
				)
			)
		);
}
//超级加密函数
function jiami($txt){
	$jiami=md5(
		base64_encode(
			sha1(
				md5(
					jiami_main(
						base64_encode(
							md5($txt)
						)
					)
				)
			)
		)
	);
	return $jiami;
}
//GUID密文出现
function create_guid(){ 
	$charid = strtoupper(md5(uniqid(mt_rand(), true))); 
	$hyphen = chr(45);
	$uuid = chr(123)
	.substr($charid, 0,8).$hyphen 
	.substr($charid, 8,4).$hyphen 
	.substr($charid,12,4).$hyphen 
	.substr($charid,16,4).$hyphen 
	.substr($charid,20,12).$hyphen 
	.substr($charid,24,12) 
	.chr(125);
	return $uuid; 
}
//屌丝随机加密
mt_srand((double) microtime() * 1000000);
function random_password($password_length = 64 , $generated_password = ""){//password_length 随机密码长度，默认10位
	$valid_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	$chars_length     = strlen($valid_characters) - 1;
	for ($i = $password_length; $i--; ) {
        //$generated_password .= $valid_characters[mt_rand(0, $chars_length)];   
		$generated_password .= substr($valid_characters, (mt_rand() % (strlen($valid_characters))), 1);
	}
	return $generated_password;
}
include("../config/header.php");
?>
<script type='text/javascript'>
	document.title = '密码在线加密 —— 在线工具';
</script>
<div class="container">
	<div class="panel panel-primary">
		<div class="panel-heading"><h3 class="panel-title">密码在线加密</h3></div>
	</div>
	<div class="form-group">
		<label>输入明码：</label>
		<form action="encryption.php" class="form" method="POST">
			<div class="input-group">
				<input type="text" name="oText" class="sy form-control" placeholder="明码..." value="<?php echo $oText;?>"/>
				<span class="input-group-btn scan-but-span">
					<input type="submit" name="Submit" class="btn btn-success" value="提交" />
				</span>
			</div>
		</form>
		<?php
			if($oText==""){
				echo '';
			}else{
				$ip=new ip();$ip->showIP();
				$md516=substr(md5($oText),8,16);
				$md532=md5($oText);
				$sha1=sha1($oText);
				$base64=base64_encode($oText);
				$PHPASS = new PasswordHash(8, true);
				$newpass = $PHPASS->HashPassword($oText);
				$super=jiami($oText);
				$common=jiami_main($oText);
				$GUID=create_guid($oText);
				$loser=random_password();
				$str=_authcode($oText,'ENCODE');
				$loserkey=$str;
				$ciphertext=passport_encrypt($oText,$ip);
		echo "<div class=\"form-group\">";
		echo "	<label>md5(16位)</label>";
		echo "	<textarea style=\"width:100%;height:35px;\" class=\"form-control\">".$md516."</textarea>";
		echo "</div>";
		echo "<div class=\"form-group\">";
		echo "	<label>md5(32位)</label>";
		echo "	<textarea style=\"width:100%;height:35px;\" class=\"form-control\">".$md532."</textarea>";
		echo "</div>";
		echo "<div class=\"form-group\">";
		echo "	<label>sha1(40位)</label>";
		echo "	<textarea style=\"width:100%;height:35px;\" class=\"form-control\">".$sha1."</textarea>";
		echo "</div>";
		echo "<div class=\"form-group\">";
		echo "	<label>base64</label>";
		echo "	<textarea style=\"width:100%;height:100px;\" class=\"form-control\">".$base64."</textarea>";
		echo "</div>";
		echo "<div class=\"form-group\">";
		echo "	<label>PasswordHash(34位)</label>";
		echo "	<textarea style=\"width:100%;height:35px;\" class=\"form-control\">".$newpass."</textarea>";
		echo "</div>";
		echo "<div class=\"form-group\">";
		echo "	<label>超级加密函数</label>";
		echo "	<textarea style=\"width:100%;height:100px;\" class=\"form-control\">".$super."</textarea>";
		echo "</div>";
		echo "<div class=\"form-group\">";
		echo "	<label>普通加密函数</label>";
		echo "	<textarea style=\"width:100%;height:100px;\" class=\"form-control\">".$common."</textarea>";
		echo "</div>";
		echo "<div class=\"form-group\">";
		echo "	<label>GUID</label>";
		echo "	<span class=\"form-control\">".$GUID."</textarea>";
		echo "</div>";
		echo "<div class=\"form-group\">";
		echo "	<label>屌丝随机加密</label>";
		echo "	<textarea style=\"width:100%;height:100px;\" class=\"form-control\">".$loser."</textarea>";
		echo "</div>";
		echo "<div class=\"form-group\">";
		echo "	<label>屌丝密钥加密</label>";
		echo "	<textarea style=\"width:100%;height:100px;\" class=\"form-control\">".$loserkey."</textarea>";
		echo "</div>";
		echo "<div class=\"form-group\">";
		echo "	<label>屌丝根据用户IP随机加密</label>";
		echo "	<textarea style=\"width:100%;height:100px;\" class=\"form-control\">".$ciphertext."</textarea>";
		echo "</div>";
				}
			?>
	</div>
	<div class="panel panel-primary">
		<div class="panel-heading"><h3 class="panel-title">加密信息</h3></div>
		<div class="panel-body">
			现已支持:md5(16位),md5(32位),sha1,base64,PasswordHash,GUID,屌丝密钥加密,根据IP随机加密<br>
			超级加密函数加密顺序：md5→base64_encode→sha1→md5→jiami_main→base64_encode→md5→最终结果<br>
			普通加密函数加密顺序：sha1→md5→sha1→md5→chop→base64_encode→最终结果
		</div>
	</div>
	<div class="panel panel-primary">
		<div class="panel-heading"><h3 class="panel-title">密文用途介绍:</h3></div>
		<div class="panel-body">
			加密，是以某种特殊的算法改变原有的信息数据，使得未授权的用户即使获得了已加密的信息，但因不知解密的方法，仍然无法了解信息的内容。 在航空学中，指利用航空摄影像片上已知的少数控制点，通过对像片测量和计算的方法在像对或整条航摄带上增加控制点的作业。<br/>
			加密技术的应用是多方面的，在此我综合了一下我常用的加密技术，下面就分别简叙它可用途<br/>
			MD5:网站帐号密码(这里用的也是最多的)、充值卡密、邀请码等等<br/>
			sha1:网站帐号密码<br/>
			base64:文字加密<br/>
			PasswordHash:网站帐号密码(博客程序常用)<br/>
			GUID:软件注册码<br/>
			超级加密函数/普通加密函数/屌丝随机加密/屌丝密钥加密/屌丝根据用户IP随机加密:都可用作邀请码、注册码等
		</div>
	</div>
</div>
<?php
include("../config/footer.php");
?>